package com.example.beikeyigou.untils;

import android.util.Log;

import androidx.fragment.app.Fragment;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.Map;
import java.util.Set;

/*
* 获取网络数据，用作工具类基类
* */
public class BaseFragment extends Fragment implements Callback.CommonCallback<String> {

    private String TAG = "Beikeyigou";
    public void postNetWork(String url, Map<String,String> map){
        RequestParams params = new RequestParams(url);
        Set<String> keySet = map.keySet();
        for (String key:keySet){
            params.addParameter(key,map.get(key));
        }
        params.setAsJsonContent(true);
        params.setBodyContentType("application/json;charset=utf-8");
        x.http().post(params,this);

    }

    public void getNetWork(String url){
        RequestParams params = new RequestParams(url);
        x.http().get(params,this);
    }

    @Override//数据获取成功调用时候的方法
    public void onSuccess(String result) {
        Log.i(TAG,"OnSuccess Result=="+result);
    }

    @Override//数据获取失败时调用的方法
    public void onError(Throwable ex, boolean isOnCallback) {
        Log.i(TAG,"OnError:result == "+ex.getMessage());
    }

    @Override
    public void onCancelled(CancelledException cex) {

    }

    @Override
    public void onFinished() {

    }
}
